package com.fate.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fate.domain.User;
import com.fate.mapper.UserMapper;
import com.fate.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{
    /**
     * 更新用户信息
     *
     * @param user
     * @return
     */
    @Override
    public boolean updateById(User user) {
        // 更新时间
        // ip
        user.setModifyTime(new Date());
        user.setUserLasttime(new Date());
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String ip = request.getRemoteHost();
        user.setUserLastip(ip);
        return super.updateById(user);
    }
}
